package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.bo.BaseParamBo;
import com.cskaoyan.bean.bo.BatchDeleteBo;
import com.cskaoyan.bean.bo.TopicBo;
import com.cskaoyan.bean.vo.BasePageData;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.TopicReadVo;
import com.cskaoyan.bean.vo.TopicVo;
import com.cskaoyan.service.PromotionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/topic")
public class TopicController {

    @Autowired
    PromotionService promotionService;

    @GetMapping("list")
    public BaseRespVo list(String title,String subtitle,BaseParamBo paramBo){
        BasePageData pageData = promotionService.getTopics(title,subtitle,paramBo);
        return BaseRespVo.ok(pageData);
    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody TopicBo topicBo){
        promotionService.deleteTopic(topicBo);
        return BaseRespVo.ok();
    }

    @GetMapping("read")
    public BaseRespVo read(Integer id){
        TopicReadVo topicReadVo = promotionService.readTopic(id);
        return BaseRespVo.ok(topicReadVo);
    }

    @PostMapping("update")
    public BaseRespVo update(@RequestBody TopicBo topicBo){
        TopicVo topicVo = promotionService.updateTopic(topicBo);
        if(topicVo == null){
            return BaseRespVo.fail("请继续修改!");
        }
        return BaseRespVo.ok(topicVo);
    }

    @RequestMapping("create")
    public BaseRespVo createTopic(@RequestBody TopicBo topicBo){
        TopicVo topicVo = promotionService.createTopic(topicBo);
        return BaseRespVo.ok(topicVo);
    }

    @PostMapping("batch-delete")
    public BaseRespVo batchDelete(@RequestBody BatchDeleteBo batchDeleteBo){
        promotionService.batchDelete(batchDeleteBo);
        return BaseRespVo.ok();
    }

}
